package com.zhiyou.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiyou.mapper.SpeakerMapper;
import com.zhiyou.pojo.Speaker;
import com.zhiyou.pojo.SpeakerExample;
import com.zhiyou.pojo.SpeakerExample.Criteria;
import com.zhiyou.pojo.Video;


@Service
public class SpeakerService {

	
	@Autowired
	private SpeakerMapper speakerMapper;
	
	public List<Speaker> selectAll(){
		
		return speakerMapper.selectByExample(new SpeakerExample());
	}
    public void saveOrUpdate(Speaker speaker){
		
		if(null!=speaker.getId() && speaker.getId()!=0){
			speakerMapper.updateByPrimaryKeyWithBLOBs(speaker);
		}else{
			
			speakerMapper.insert(speaker);
		}
	}
    public int delById(int id){
		return speakerMapper.deleteByPrimaryKey(id);
	}
   public int delBatchByIds(Integer[] ids){
		
		SpeakerExample example = new SpeakerExample();
		// ctrl + 1  �Զ�����ֶ�
		 Criteria createCriteria = example.createCriteria();
		 //delete from video where id in(1,2,3,5);
		 
		 //����ת��Ϊһ������
		 List<Integer> list = new ArrayList<Integer>();
		 Collections.addAll(list, ids);
		 createCriteria.andIdIn(list);
		return speakerMapper.deleteByExample(example);
	}
	
	public Speaker selectById(int id){
		
		return speakerMapper.selectByPrimaryKey(id);
	}
}
